package com.foreknow.elm.controller;

import com.foreknow.elm.po.Deliveryaddress;
import com.foreknow.elm.service.BusinessService;
import com.foreknow.elm.service.DeliveryAddressService;
import com.foreknow.elm.service.impl.BusinessServiceImpl;
import com.foreknow.elm.service.impl.DeliveryAddressServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class DeliveryAddressController {
    /**
     * 请求地址  http://localhost:8080/MavenElmWebProject/DeliveryAddressController/listDeliveryAddressByUserId?userId=12345671111
     * @param request
     * @return
     */
    public  Object listDeliveryAddressByUserId(HttpServletRequest request){
        //获取请求参数
        String userId= request.getParameter("userId");
        //调用Service层的方法
       DeliveryAddressService service = (DeliveryAddressService) new DeliveryAddressServiceImpl();
       List<Deliveryaddress> list = service.listDeliveryAddressByUserId(userId);
        return list;
    }
    /**
     * 请求地址  http://localhost:8080/MavenElmWebProject/DeliveryAddressController/getDeliveryAddressById?daId=2
     * @param request
     * @return
     */

    public  Object getDeliveryAddressById(HttpServletRequest request){
        //获取请求参数
        String daId= request.getParameter("daId");
        //调用Service层的方法
        DeliveryAddressService service = new DeliveryAddressServiceImpl();
        List<Deliveryaddress> list = service.getDeliveryAddressById(Integer.valueOf(daId));
        return list;
    }

    /**
     * 请求地址  http://localhost:8080/MavenElmWebProject/DeliveryAddressController/saveDeliveryAddress?contactName=张三&contactSex=1&contactTel=dfecds&address=法国&userId=189262695
     * @param request
     * @return
     */
    public  int saveDeliveryAddress(HttpServletRequest request){
        //获取请求参数
        //contactName,contactSex,contactTel,address,userId
        String contactName= request.getParameter("contactName");
        String  contactSex = request.getParameter("contactSex");
        String contactTel= request.getParameter("contactTel");
        String address= request.getParameter("address");
        String userId= request.getParameter("userId");
        //调用Service层的方法
        DeliveryAddressService service = new DeliveryAddressServiceImpl();
        Integer result = service.saveDeliveryAddress(contactName,Integer.valueOf(contactSex),contactTel,address,userId);

        return result;
    }
    /**
     * 请求地址  http://localhost:8080/MavenElmWebProject/DeliveryAddressController/updateDeliveryAddress?contactName=李四&contactSex=1&contactTel=122222&address=法国巴黎&userId=8080&daId=8
     * @param request
     * @return
     */
    public int updateDeliveryAddress(HttpServletRequest request){
        //获取请求参数
        String contactName= request.getParameter("contactName");
        String  contactSex = request.getParameter("contactSex");
        String contactTel= request.getParameter("contactTel");
        String address= request.getParameter("address");
        String userId= request.getParameter("userId");
        String daId = request.getParameter("daId");
        //调用Service层的方法
        DeliveryAddressService service = new DeliveryAddressServiceImpl();
        int update = service.updateDeliveryAddress(Integer.valueOf(daId),contactName,Integer.valueOf(contactSex),contactTel,address,userId);

        return update;
    }
    /**
     * 请求地址  http://localhost:8080/MavenElmWebProject/DeliveryAddressController/removeDeliveryAddress?daId=7
     * @param request
     * @return
     */
    public int removeDeliveryAddress(HttpServletRequest request){
        //获取请求参数
        String daId= request.getParameter("daId");
        //调用Service层的方法
        DeliveryAddressService service = new DeliveryAddressServiceImpl();
        int del = service.removeDeliveryAddress(Integer.valueOf(daId));

        return del;
    }
}


